<%@ page language="java" isELIgnored="false"%>
<%@include file="../common/taglib.jsp"%>

<div id="Conteudo">
	<html:form action="contato">
		<html:hidden property="codigo"></html:hidden>
		<html:hidden property="method"></html:hidden>
		<html:hidden property="state"></html:hidden>
		<html:hidden property="searchMethod" value="br.com.ia.business.ContatoBusiness.buscarContatoPorNomeCodEmpresa(java.lang.String:nome, java.lang.Integer:empresa.codigo)"/>
		<h1><bean:message key="contato.label.title"/>:<span><bean:message key="subtitulo.label.consulta"/></span> </h1>
		<h3 class="acordeon" onClick="EN_slideFiltro(this,'menu_block1');"><strong>Buscar</strong></h3>
		<div class="divAcordeon" id="menu_block1">	
			<div class="campo">
				<label>
				<bean:message key="contato.label.nome"/>
				</label> 	
				<html:text property="nome" style="width:500px;" maxlength="200"></html:text>
			</div>
			<div class="campo">
				<label>
					<bean:message key="empresa.label.empresa"/>
				</label> 
				<html:select property="empresa.codigo">
				<html:option value="">Todas</html:option>
					<trex:options source="br.com.ia.business.EmpresaBusiness.retrieveAll()" property="codigo" labelProperty="nome"/>
				</html:select>
			</div>
			
			<div id="BotoesFiltro">
				<input type="button" class="BtNovo" value="Novo" onclick="insert()"/>
				<input type="submit" class="BtPesquisar" value="Pesquisar" onclick="search()"/>
			</div>			
		</div>
	

	</html:form>
	<h3 class="acordeon" onClick="EN_slideFiltro(this,'menu_block2');"><strong>Resultado</strong><span><!-- Agrupamento 1 --></span></h3>
	<div class="divAcordeon datagrid" id="menu_block2">
		<display:table name="list"	id="contato" cellpadding="0" cellspacing="0">
				
			<display:column title="Nome"href="contato.do?method=prepareUpdate" paramId="codigo" paramProperty="codigo">
				
				<c:out value="${contato.nome}"/>
			</display:column>
			
			<display:column title="Telefone">
				<c:out value="${contato.telefone}"/>
			</display:column>
					
			<display:column>
				<a class="aExcluir" href="javascript:deletar(<c:out value='${contato.codigo}'/>);"></a>	
			</display:column>		
		
	</display:table>
	</div>
</div>

<script>

	/**
	 * Consultar contato
	 */
	function search(){
		document.ContatoForm.method.value = 'search';		
		document.ContatoForm.submit();
	}
	
	/**
	 * Incluir contato
	 */
	function insert(){
	
		document.ContatoForm.method.value = 'prepareInsert';
		document.ContatoForm.submit();	
	}
	
	/**
	 * Excluir contato
	 */
	function deletar(codigo) {
		
		if(confirm('Deseja realmente excluir esse Contato?')){;
			document.ContatoForm.method.value = 'delete';
			document.ContatoForm.codigo.value = codigo;
			document.ContatoForm.submit();
		}
	}
	
</script>